#    Rubatom
#    Copyright (c) 2014 Sebastian Dufner
#
#    This file is part of Rubatom.
#
#    Rubatom is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Rubatom is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

module Rubatom
  class Block
    class Dictionary
      def self.[](key)
        @@dict[key] || @@dict_inv[key]
      end

      @@dict = {
        empty: 0,
        core_id: 1,
        power_id: 2,
        shield_id: 3,
        salvage_controller_id: 4,
        hull_id: 5,
        weapon_controller_id: 6,
        turret_dock_id: 7,
        thruster_id: 8,
        explosive_id: 14,
        radar_jamming_id: 15,
        weapon_id: 16,
        cloaking_id: 22,
        salvage_id: 24,
        repair_id: 30,
        missile_dumb_id: 32,
        missile_dumb_controller_id: 38,
        repair_controller_id: 39,
        missile_heat_id: 40,
        missile_heat_controller_id: 46,
        cockpit_id: 47,
        missile_fafo_id: 48,
        missile_fafo_controller_id: 54,
        light_id: 55,
        gravity_id: 56,
        light_beacon_id: 62,
        glass_id: 63,
        terrain_ice_id: 64,
        deathstar_core_id: 65,
        hull_color_purple_id: 69,
        hull_color_brown_id: 70,
        terrain_extranium_id: 72,
        terrain_rock_id: 73,
        terrain_sand_id: 74,
        hull_color_black_id: 75,
        hull_color_red_id: 76,
        hull_color_blue_id: 77,
        hull_color_green_id: 78,
        hull_color_yellow_id: 79,
        terrain_lava_id: 80,
        hull_color_white_id: 81,
        terrain_earth_top_dirt: 82,
        terrain_earth_top_rock: 83,
        terrain_tree_trunk_id: 84,
        terrain_tree_leaf_id: 85,
        terrain_vines_id: 85,
        terrain_water: 86,
        water: 86,
        terrain_dirt_id: 87,
        turret_dock_enhance_id: 88,
        terrain_cactus_id: 89,
        terrain_purple_alien_top: 90,
        terrain_purple_alien_rock: 91,
        terrain_purple_alien_vine: 92,
        terrain_grass_sprite: 93,
        player_spawn_module: 94,
        terrain_brownweed_sprite: 95,
        terrain_marstentacles_sprite: 96,
        terrain_alienvine_sprite: 97,
        terrain_grassflowers_sprite: 98,
        terrain_longweed_sprite: 99,
        terrain_tallshroom_sprite: 100,
        terrain_purspire_sprite: 101,
        terrain_tallgrassflowers_sprite: 102,
        terrain_minicactus_sprite: 103,
        terrain_redshroom_sprite: 104,
        terrain_purptacles_sprite: 105,
        terrain_tallflowers_sprite: 106,
        terrain_rock_sprite: 107,
        terrain_alienflowers_sprite: 108,
        terrain_yhole_sprite: 109,
        landing_element: 112,
        lift_element: 113,
        recycler_element: 114,
        stash_element: 120,
        ai_element: 121,
        door_element: 122,
        build_block_id: 123,
        terrain_gold_id: 128,
        terrain_iridium_id: 129,
        terrain_mercury_id: 130,
        terrain_palladium_id: 131,
        terrain_platinum_id: 132,
        terrain_lithium_id: 133,
        terrain_magnesium_id: 134,
        terrain_titanium_id: 135,
        terrain_uranium_id: 136,
        terrain_polonium_id: 137,
        terrain_mars_top: 138,
        terrain_mars_rock: 139,
        terrain_mars_dirt: 140,
        terrain_negacide_id: 206,
        terrain_quantacide_id: 207,
        terrain_negagate_id: 208,
        terrain_metate_id: 209,
        terrain_insaniunm_id: 210,
        factory_input_id: 211,
        factory_input_enh_id: 212,
        factory_power_cell_id: 213,
        factory_power_cell_enh_id: 214,
        factory_power_coil_id: 215,
        factory_power_coil_enh_id: 216,
        factory_power_block_id: 217,
        factory_power_block_enh_id: 218,
        power_cell: 219,
        power_coil: 220,
        terrain_iceplanet_surface: 274,
        terrain_iceplanet_rock: 275,
        terrain_iceplanet_wood: 276,
        terrain_iceplanet_leaves: 277,
        terrain_iceplanet_spike_sprite: 278,
        terrain_iceplanet_icecrag_sprite: 279,
        terrain_iceplanet_icecoral_sprite: 280,
        terrain_iceplanet_icegrass_sprite: 281,
        light_red: 282,
        light_blue: 283,
        light_green: 284,
        light_yellow: 285,
        terrain_iceplanet_crystal: 286,
        terrain_redwood: 287,
        terrain_redwood_leaves: 288,
        fixed_dock_id: 289,
        fixed_dock_id_enhancer: 290,
        faction_block: 291,
        faction_hub_block: 292,
        power_cap_id: 331,
        power_drain_beam_computer: 332,
        power_drain_beam_module: 333,
        power_supply_beam_computer: 334,
        power_supply_beam_module: 335,
        pulse_controller_id: 344,
        pulse_id: 345,
        faction_public_exception_id: 346,
        shop_block_id: 347
      }
      @@dict_inv = @@dict.invert
    end

    def initialize(id, hp: 0, orientation: 0, active: false)
      @id, @hp, @orientation, @active = id, hp, orientation, active
    end

    Empty = Block.new(0).freeze

    attr_reader :id
    attr_writer :id
    attr_reader :hp
    attr_writer :hp
    attr_reader :orientation
    attr_writer :orientation

    def active?; @active; end
    def active=(active); @active = active; end

    def name
      Dictionary[@id]
    end
  end
end
